<div class="page-content">
    <script>var ForExamSearch =<{$ForExamSearch}>;</script>
    <div class="panel panel-default">
        <div class="panel-heading"> 编辑课程 <a class="btn btn-primary btn-xs" href="<{:U('Subject/index')}>">返回列表</a></div>
        <div class="panel-body">
            <form id="form" class="form-horizontal" enctype="multipart/form-data" action="<{:U('Subject/add_subject')}>"
                  autocomplete="off" method="post" novalidate="novalidate">
                <input type="hidden" name="id" value="<{$data.subjectid}>">
                <div class="form-group" id="subject_class_div">
                    <label class="col-sm-2 control-label">所属班级</label>
                    <div class="col-sm-7">
                        <input type="hidden" name="subject_class" value="<{$data.subject_class}>">
                        <div id="business-wrapper">
                            <volist name="subject_class" id="vo"><span onclick="select_ExamSearch(this)"
                                                                       class="subject <if condition=" $data['subject_class']
                                eq $vo['id']">active
                                </if>
                                " data-type='<{$vo.type}>' data-id="<{$vo['id']}>"
                                data-name="subject_class"><{$vo.name}></span> </volist>
                        </div>
                        <small class="help-block"></small>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group" id="subjectsetting_div">
                    <label class="col-sm-2 control-label">课程题型</label>
                    <div class="col-sm-7">
                        <div id="business-wrapper">
                            <volist name="questype" id="vo"><span class="subjectsetting <if condition=" $vo['choose'] eq
                                1">select
                                </if>
                                " data-id="<{$vo['questid']}>" data-name="subjectsetting"><{$vo.questype}></span>
                                <if condition="$vo['choose'] eq 1">
                                    <input type="hidden" name="subjectsetting[]" value="<{$vo.questid}>"/>
                                </if>
                            </volist>
                        </div>
                        <small class="help-block"></small>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">考试科目</label>
                    <div class="col-sm-7">
                        <select name="bkjb">
                        </select>

                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">课程名</label>
                    <div class="col-sm-7">
                        <input type="text" name="subject" class="form-control" value="<{$data.subject}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">子课程</label>
                    <div class="col-sm-7">
                        <p><a href="javascript:" class="btn btn-primary btn-xs" onclick="add_childs()">增加</a></p>
                        <div id="childs_box">
                            <volist name="data_childs" id="vo1">
                                <div class="clearfix" style="margin-bottom:5px">
                                    <div class="col-sm-7">
                                        <input type="text" name="childs[]" value="<{$vo1.subject}>" class="form-control"/>
                                    </div>
                                    <div class="col-sm-3"><a href="javascript:" class="btn btn-primary btn-xs"
                                                             onclick="del_childs(this)">删除</a></div>
                                </div>
                            </volist>
                        </div>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <style>
                    #childs_box .col-sm-7 {
                        padding-left: 0px
                    }
                </style>
                <script>
                    function add_childs() {
                        var html = '<div class="clearfix" style="margin-bottom:5px">';
                        html += '<div class="col-sm-7"><input type="text" name="childs[]" value=""  class="form-control"/></div>';
                        html += ' <div class="col-sm-3"><a href="javascript:" class="btn btn-primary btn-xs" onclick="del_childs(this)">删除</a></div>';
                        html += '<div>';
                        $("#childs_box").append(html);
                    }
                    function del_childs(_this) {
                        $(_this).parent().parent().remove();
                    }

                </script>
                <div class="form-group">
                    <label class="col-sm-2 control-label">价格</label>
                    <div class="col-sm-7">
                        <input type="text" name="price" class="form-control" value="<{$data.price}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">购买获得学币</label>
                    <div class="col-sm-7">
                        <input type="text" name="tujibi" class="form-control" value="<{$data.tujibi}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">购买优惠：</label>
                    <div class="col-sm-7">
                        <input type="text" name="school_num_for_buy" class="form-control"
                               value="<{$data.school_num_for_buy}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">推广说明：</label>
                    <div class="col-sm-7 mgt10"> C：线下班级常量， O：线下班级倍率， R(1,10)：1到10随机数， P:系统变量
                        如：50*O-P*(50*0.6)+R(1,10)-C
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">校友推广得：</label>
                    <div class="col-sm-7">
                        <input type="text" name="school_num_for_seller" class="form-control"
                               value="<{$data.school_num_for_seller}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">校园合伙人得</label>
                    <div class="col-sm-7">
                        <input type="text" name="agent_num_for_seller" class="form-control"
                               value="<{$data.agent_num_for_seller}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>

                <!--<div class="form-group">
                                <label class="col-sm-2 control-label">推广获得学币随机数</label>
                                <div class="col-sm-7">
                                                <input type="text"  placeholder="如设置100，获得佣金会加上1到100的随机数" name="randMoney" class="form-control" value="<{$data.randMoney}>">
                                </div>
                                <div class="col-sm-3"> </div>
                </div>-->
                <div class="form-group">
                    <label class="col-sm-2 control-label">购买获得提问次数</label>
                    <div class="col-sm-7">
                        <input type="text" name="ask_num" class="form-control" value="<{$data.ask_num}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">结课时间</label>
                    <div class="col-sm-7">
                        <input class="input-small datetimepicker" data-date="" data-date-format="yyyy-mm-dd" type="text"
                               name="end_date" size="10" id="stime" value="<{$data.end_date}>" autocomplete="off">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group" id="picname_div">
                    <label class="col-sm-2 control-label">图片</label>
                    <div class="col-sm-7">
                        <label class="btn btn-primary">上传课程封面
                            <input id="picname" name="picname" onchange="previewImage(this);check()"
                                   class="fileupload hide" type="file" data-target="cover">
                        </label>
                        <span> 建议:215*135</span>
                        <small class="help-block"></small>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <div class="col-sm-7 col-sm-offset-2 gallery" data-name="cover">
                        <div class="thumbnail">
                            <div id="preview">
                                <if condition="$data['picname']"><img src="__Img__/<{$data.picname}>" width="50"
                                                                      style="display: inline;"/></if>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">微信App课程优势</label>
                    <div class="col-sm-7">
                        <textarea style="width: 680px; height: 400px;" class="input_a1" id="textarea-content"
                                  name="content" rows="2"><{$data.content}></textarea>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">课程优势</label>
                    <div class="col-sm-7">
                        <textarea style="width: 680px; height: 400px;" class="input_a1" name="rntro" rows="2"><{$data.rntro}></textarea>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">常见问题</label>
                    <div class="col-sm-7">
                        <textarea style="width: 680px; height: 400px;" class="input_a1" name="FAQ" rows="2"><{$data.FAQ}></textarea>
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">可申请奖学金分数线</label>
                    <div class="col-sm-7">
                        <input type="text" name="scholarship_score" class="form-control"
                               value="<{$data.scholarship_score}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">可申请重学分数线</label>
                    <div class="col-sm-7">
                        <input type="text" name="relearn_score" class="form-control" value="<{$data.relearn_score}>">
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-7">
                        <button type="submit" onclick="return check()" class="btn btn-primary">保存课程</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<link rel="stylesheet" href="__PUBLIC__/kindeditor-4.1.10/themes/default/default.css"/>
<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/kindeditor-min.js"></script>
<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript">
    var editor;
    KindEditor.ready(function (K) {

        editor1 = K.create('textarea[name="content"]', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            formatUploadUrl: false,
            uploadJson: '<php>echo "http://".$_SERVER["HTTP_HOST"];</php><{:api_url("Kindeditor/uploadJson")}>',
            afterBlur: function () {
                this.sync();
            }
        });


        editor2 = K.create('textarea[name="rntro"]', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            formatUploadUrl: false,
            uploadJson: '<php>echo "http://".$_SERVER["HTTP_HOST"];</php><{:api_url("Kindeditor/uploadJson")}>',
            afterBlur: function () {
                this.sync();
            }
        });

        editor2 = K.create('textarea[name="FAQ"]', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            formatUploadUrl: false,
            uploadJson: '<php>echo "http://".$_SERVER["HTTP_HOST"];</php><{:api_url("Kindeditor/uploadJson")}>',
            afterBlur: function () {
                this.sync();
            }
        });


    });

</script>
<script type="text/javascript">

    $('.subject').selectOne(function (ele, dataId, name) {
        check();
    });
    $('.subjectsetting').selectMuti();


</script>
<script>
    function check() {
        var leng = $("#subjectsetting_div .select").length;
        var leng2 = $("#subject_class_div .active").length;
        var _img_ = $("#preview img").length;

        var flag = 0;
        if (leng == 0) {
            $("#subjectsetting_div").addClass("has-error");
            $("#subjectsetting_div").find(".help-block").html("科目题型至少选择一项");
            flag = 1;
        } else {
            $("#subjectsetting_div").removeClass("has-error").addClass("has-success");
            $("#subjectsetting_div").find(".help-block").html("");
        }
        if (leng2 == 0) {
            $("#subject_class_div").addClass("has-error");
            $("#subject_class_div").find(".help-block").html("请选择所属学科");
            flag = 1;
        } else {
            $("#subject_class_div").removeClass("has-error").addClass("has-success");
            $("#subject_class_div").find(".help-block").html("");
        }
        if (_img_ == 0) {
            $("#picname_div").addClass("has-error");
            $("#picname_div").find(".help-block").html("请选择图片");
            flag = 1;
        } else {
            $("#picname_div").removeClass("has-error").addClass("has-success");
            $("#picname_div").find(".help-block").html("");
        }

        if (flag == 1) {
            return false;
        } else {
            $(".form-horizontal").data('bootstrapValidator').resetForm();
            return true;
        }


    }
    $(function () {
        $(".form-horizontal").bootstrapValidator({
            message: '您填入的值不合法',
            fields: {
                subject_class: {
                    message: '科目名称',
                    validators: {
                        notEmpty: {
                            message: '科目名称不能为空'
                        },
                    }
                },
                subject: {
                    message: '课程名',
                    validators: {
                        notEmpty: {
                            message: '课程名不能为空'
                        },
                    }
                },
                /* end_date: {
                 message: '结课时间',
                 validators: {
                 notEmpty: {
                 message: '结课时间不能为空'
                 },
                 }
                 },*/

                price: {
                    message: '价格',
                    validators: {
                        notEmpty: {
                            message: '价格不能为空'
                        },
                        greaterThan: {
                            value: 0,
                            message: '价格不能小于0'
                        },
                    }
                },

                school_num_for_buy: {
                    message: '购买优惠',
                    validators: {
                        notEmpty: {
                            message: '购买优惠不能为空'
                        },
                        remote: {
                            message: '购买优惠算法不正确,允许输入【O,P,R,数字，运算符】',
                            data: {name: 'school_num_for_buy'},
                            url: '<{:U("Subject/check_subject")}>'
                        }
                    }

                },
                school_num_for_seller: {
                    message: '校友合伙人推广',
                    validators: {
                        notEmpty: {
                            message: '校友推广得不能为空'
                        },
                        remote: {
                            message: '算法不正确,允许输入【O,P,R,C,数字，运算符】',
                            data: {name: 'school_num_for_seller'},
                            url: '<{:U("Subject/check_subject")}>'
                        }
                    },

                },


                agent_num_for_seller: {
                    message: '校园合伙人推广',
                    validators: {
                        notEmpty: {
                            message: '不能为空'
                        },
                        remote: {
                            message: '算法不正确,允许输入【O,P,R,C,数字，运算符】',
                            data: {name: 'agent_num_for_seller'},
                            url: '<{:U("Subject/check_subject")}>'
                        }
                    }
                },
                tujibi: {
                    message: '学币',
                    validators: {
                        notEmpty: {
                            message: '学币不能为空'
                        },
                        greaterThan: {
                            value: 0,
                            message: '学币不能小于0'
                        },
                    }
                },
                ask_num: {
                    message: '提问次数',
                    validators: {
                        notEmpty: {
                            message: '提问次数不能为空'
                        },
                        greaterThan: {
                            value: 0,
                            message: '提问次数不能小于0'
                        },
                    }
                },
            }

        });


    });

    select_ExamSearch("", "<{$data.bkjb}>");
    function select_ExamSearch(_this, bkjb) {
        if (typeof(_this) == "string") {
            var class_wrapper = $("#business-wrapper").find('.active');
        } else {
            class_wrapper = $(_this);
        }

        var type = 0;
        if ($(class_wrapper).length > 0) {
            type = $(class_wrapper).attr("data-type");
        }
        var html = "";
        if (ForExamSearch[type]) {
            $.each(ForExamSearch[type], function (i, vo) {
                html += '<option value="' + vo.value + '">' + vo.text + '</option>';
            })
        }
        if (html == "") {
            $("[name='bkjb']").parents(".form-group").hide();
        } else {
            $("[name='bkjb']").parents(".form-group").show();
            $("[name='bkjb']").html(html);
        }
        if (bkjb != "" && typeof(bkjb) == "string") {
            $("[name='bkjb']").val(bkjb);
            $("[name='bkjb']").find("[value='" + bkjb + "']").prop("selected", true)
        }
    }
</script>
